<template>
  <div class="login">
    <div class="header width-1200">
      <div>
        <img src="../assets/images/logo.png" alt="">
      </div>
    </div>
    <img src="../assets/images/rightImage.png" alt="" class="header-bg">
    <div class="body width-1200">
      <div class="left-title">
        花小梦
        <br>
        后台管理系统
        <div class="left-title-center">
          <p>
            <img src="../assets/images/2.png" alt="">
            组织变革 + 灵活用工
          </p>
          <p>
            <img src="../assets/images/2.png" alt="">
            以科技为组织共享赋能 与自由职业者共创价值
          </p>
        </div>
        <img src="../assets/images/left-bottom.png" alt="" class="left-title-bottom">
        <div class="foot"><p>广告合作 免责声明 友情链接 联系我们 关于我们 用户协议</p><p>Copyright © 2022  - 苏ICP备XXXXX号  </p></div>
      </div>
      <div class="right-login">
        <div style="margin-top: 120px">
          <el-form :model="loginForm" :rules="loginRules" ref="loginForm" class="demo-ruleForm">
            <el-form-item prop="username" style="margin-left: 50px">
              <el-input v-model="loginForm.username" placeholder="请输入您的账号" style="width: 300px;"/>
            </el-form-item>
            <el-form-item prop="password" style="margin-top: 30px;margin-left: 50px">
              <el-input v-model="loginForm.password" placeholder="请输入您的密码" style="width: 300px;"  show-password/>
            </el-form-item>
          </el-form>
        </div>
        <el-button type="primary" style="width: 300px;margin-left: 50px;margin-top: 25px" @click.native.prevent="handleLogin">
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
      </div>
      <img src="../assets/images/login-right.png" alt="" class="right-img">
    </div>
  </div>
</template>

<script>

export default {
  name: "Login",
  data () {
    return {
      loginForm: {
        username: "",
        password: "",
        isLock: false
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" }
        ]
      },
      loading: false,
      redirect: undefined
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created () {
    // nothing
  },
  methods: {
    handleLogin () {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          this.$store.dispatch("Login", this.loginForm).then(() => {
            this.$router.push({ path: this.redirect || "/" }).catch(() => { });
          }).catch(() => {
            this.loading = false;
          });
        }
      });
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
  .login{
    width: 100%;
    height: 100%;
    min-height: 850px;
    position: relative;
    overflow: hidden;
    background-color: white;
  }
  .login .header {
    height: 100px;
  }
  .width-1200 {
    width: 1200px;
  }
  .width-1000, .width-1200 {
    position: relative;
    margin: auto;
  }
  .login .header div img {
    display: block;
    height: 40px;
  }
  .login .header-bg {
    position: absolute;
    top: 0;
    right: -39px;
    height: 100%;
    z-index: 2;
  }
  .login .header div {
    width: 1005px;
    margin: auto;
    padding-top: 60px;
    z-index: 4;
    background-color: #fdfdff;
    position: absolute;
    top: 0;
    left: 0;
  }
  .login .body {
    height: calc(100% - 100px);
    background-color: #fdfdff;
    position: relative;
  }
  .login .body .left-title {
    font-size: 42px;
    font-weight: 500;
    color: #000;
    width: 1005px;
    z-index: 4;
    padding-top: 60px;
    background-color: #fdfdff;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
  }
  .login .body .left-title .left-title-center {
    margin: 35px 0;
  }
  .login .body .left-title .left-title-center p {
    position: relative;
    font-size: 22px;
    line-height: 34px;
    padding-left: 60px;
    font-weight: 400;
    margin: 12px 0;
  }
  .login .body .left-title .left-title-center p img {
    position: absolute;
    left: 0;
    top: 2px;
    height: 30px;
    width: 30px;
  }
  .login .body .left-title .left-title-bottom {
    display: block;
    margin-left: -16px;
    width: 765px;
  }
  .login .foot {
    padding-top: 60px;
    width: 1200px;
  }
  .login .foot p {
    display: block;
    text-align: center;
    color: #777;
    font-size: 14px;
    line-height: 28px;
    margin: 0;
  }
  .login .body .right-login {
    position: absolute;
    top: 60px;
    right: 0;
    height: 420px;
    width: 400px;
    background: #fff;
    -webkit-box-shadow: 0 0 29px 2px rgb(35 32 31 / 5%);
    box-shadow: 0 0 29px 2px rgb(35 32 31 / 5%);
    border-radius: 10px;
    z-index: 7;
  }
  .login .body .right-img {
    position: absolute;
    top: 120px;
    right: -80px;
    z-index: 6;
  }
</style>
